package org.raymond.icloud.common.core.mybatis;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONValidator;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.beans.PropertyEditorSupport;

public class OrderItemEditor extends PropertyEditorSupport {

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if(StringUtils.isBlank(text)) return;

        JSONValidator jv = JSONValidator.from(text);
        if(jv.validate() && jv.getType() == JSONValidator.Type.Object) {
            OrderItem oi = JSONObject.parseObject(text, OrderItem.class);
            oi.setColumn(StringUtils.camelToUnderline(oi.getColumn()));
            setValue(oi);
        }
    }
}
